using UnityEngine;
using System.Collections;

public class AnimationAutoPlay : MonoBehaviour
{
	
	// Use this for initialization
	UICheckbox checkBox;
	
	void Start ()
	{
		animation ["idle"].wrapMode = WrapMode.Loop;
		animation ["idle"].speed = 0.25f;
		
		animation ["skill"].wrapMode = WrapMode.ClampForever;
		animation ["skill"].speed = 0.25f;
		
		AnimationEvent aniEvent = new AnimationEvent();
		aniEvent.functionName = "CrossFadeIdle";
		aniEvent.time = animation ["skill"].length;
		animation.GetClip("skill").AddEvent(aniEvent);
		
		animation.CrossFade ("skill", 0.1f);
		
		InvokeRepeating("RepeatPlay",0,5);
	}
	
	void Update(){
		
	}
	
	/*
	void OnEnable ()
	{
		UICheckbox chk = transform.parent.GetComponent<UICheckbox>();
		if (chk != null) OnActivate(chk.isChecked);
	}
	
	void OnActivate(bool isActive){
		if(isActive) animation.CrossFade("skill",0.3f);
	}
	*/
	void CrossFadeIdle(){
		animation.CrossFade("idle",0.3f);
	}
	
	void RepeatPlay(){
		animation.CrossFade("skill",0.3f);
	}
	
	public void CheckedPlay(){
		animation.CrossFade("skill",0.3f);
	}
}
